from django.db import models
from iperscribo.pages.models import Page
from iperscribo.utils import newUID
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic

MESSAGE_TYPE = (
    (0, 'Comment'),
    (1, 'Question'),
    (2, 'Todo'),
)

# Create your models here.
class Message(models.Model):
    uid = models.CharField(max_length=40, default=newUID, primary_key=True)
    type = models.IntegerField(choices=MESSAGE_TYPE)
    owner = models.ForeignKey(User, related_name='messages')
    #page = models.ForeignKey('pages.Page')
    creation_date = models.DateTimeField(auto_now_add=True)
    text = models.TextField()
    document_type = models.ForeignKey(ContentType)
    document_uid = models.CharField(max_length=40)
    document = generic.GenericForeignKey('document_type', 'document_uid')

    def __unicode__(self):
        return '%s - %s' % (self.uid, self.type) 
    
    
    